{% extends "base.html" %}

{% block stylesheets %}
  <link rel="stylesheet" type="text/css" href="/assets/css/pass_list.css">
{% endblock %}

{% block pre_body %}
  <div id="instruments" class="flex-container">
    {% if constant('Config\\Config::ENABLE_SATVIS') == 'true' %}
      <div id="satvis" class="d-none d-sm-block flex-child">
        <iframe name="satvis" src="https://satvis.space/?elements=Point,Label,Orbit%20track,Sensor%20cone&layers=OfflineHighres&gs={{ constant('Config\\Config::BASE_STATION_LAT') }},{{ constant('Config\\Config::BASE_STATION_LON') }}&tags=Weather"></iframe>
      </div>
    {% endif %}

    {% if constant('Config\\Config::ENABLE_ANIMATION') == 'true' %}
      <div id="noaa-animation" class="d-none d-sm-block flex-child">
        <video playsinline autoplay muted loop controls src="{{ constant('Config\\Config::ANIMATION_VIDEO_FILE') }}" width="100%" height="100%" type="video/mp4"></video>
      </div>
    {% endif %}
  </div>
{% endblock %}

{% block body %}
  <table class="table table-bordered table-sm table-striped" id="passes">
    <thead class="thead-dark">
      <tr class="text-center">
        <th scope="col">{{ lang['satellite'] }}</th>
        <th scope="col">{{ lang['pass_start'] }}</th>
        <th scope="col">{{ lang['pass_end'] }}</th>
        <th scope="col">{{ lang['max_elev'] }}</th>
        <th scope="col" class="d-none d-sm-table-cell">{{ lang['pass_start_azimuth'] }}</th>
        <th scope="col" class="d-none d-sm-table-cell">{{ lang['travel_direction'] }}</th>
      </tr>
    </thead>
    <tbody>
      {% set now_ms = 'now'|date('U') %}
      {% set cur_date = now_ms|date('m/d/y') %}
      {% set last_date = 0 %}

      {% if pass.list|length <= 0 %}
        <tr>
          <td colspan="6" class="no-passes">0 {{ lang['passes'] }}</td>
        </tr>
      {% else %}
        {% for pass in pass.list %}
          {% set pass_start = pass.pass_start|date('H:i:s') %}
          {% set pass_end = pass.pass_end|date('H:i:s') %}
          {% set cur_date = pass.pass_start|date('m/d/y') %}
          {% set pass_end_ms = pass.pass_end|date('U') %}

          {% if last_date < cur_date %}
            <tr class="date-separator">
              <td colspan="6">{{ cur_date|date(constant('Config\\Config::PASSES_DATE_FORMAT')) }}</td>
            </tr>
            {% set last_date = cur_date %}
          {% endif %}

          <tr{% if pass.is_active == false or pass_end_ms < now_ms %} class="inactive"{% endif %}>
            <td{% if prev_pass_end >= pass.pass_start %} class="conflict"{% endif %}>
              {% if prev_pass_end >= pass.pass_start %}<i class="fa fa-exclamation-triangle conflict-icon" data-toggle="tooltip" data-placement="right" title="{{ lang['conflicting_pass'] }}"></i>{% endif %}
              {% if constant('Config\\Config::ENABLE_SATVIS') == 'true' %}
                <a href='https://satvis.space/?elements=Point,Label,Orbit%20track,Sensor%20cone&layers=OfflineHighres&tags=Weather&sat={{ pass.sat_name }}&gs={{ constant('Config\\Config::BASE_STATION_LAT') }},{{ constant('Config\\Config::BASE_STATION_LON') }}' target='satvis'>{{ pass.sat_name }}</a>
              {% else %}
                {{ pass.sat_name }}
              {% endif %}
            </td>
            <td class="text-center">{{ pass_start }}</td>
            <td class="text-center">{{ pass_end }}</td>
            <td class="text-center">
              {{ pass.max_elev }}&#176;
              {% if pass.azimuth_at_max != "" %}
                {% if pass.azimuth_at_max >= 0 and pass.azimuth_at_max <= 180 %}E{% else %}W{% endif %}
              {% endif %}
            </td>
            <td class="text-center d-none d-sm-table-cell">{% if pass.pass_start_azimuth != "" %}{{ pass.pass_start_azimuth }}&#176;{% endif %}</td>
            <td class="text-center d-none d-sm-table-cell">{% if pass.direction != "" %}{{ pass.direction }}{% endif %}</td>
          </tr>

          {% set prev_pass_end = pass.pass_end %}
        {% endfor %}
      {% endif %}
    </tbody>
  </table>

{% endblock %}

{% block js_includes %}
  <script src="/assets/js/tooltips.js"></script>
{% endblock %}
